package day02;

/**
 * @author Jetwang
 * @version 1.0
 * @since 2023/3/12 9:45
 */
public class Offer16Non {

    public double myPow(double x, int n) {
        double res = 1;
        long y = n;
        if (n < 0) {
            y = -y;
            x = 1 / x;
        }
        while(y > 0) {
            if (y % 2 == 1) {
                res = res * x;
            }
            x = x * x;
            y = y / 2;
        }
        return res;
    }
}
